package com.example.learn.controller;

import com.example.learn.utils.R;
import com.example.learn.utils.UploadUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/*
* 上传图片 controller
* */
@Controller
@RequestMapping("/upload")
public class UploadController {

    @ResponseBody
    @PostMapping("/img")
    public R uploadImage(MultipartFile file){
        // 获取图片路径
        String imgPath = UploadUtils.upload(file);
        // 如果上传成功
        if(imgPath != null) {
            return R.success(imgPath, "上传成功");
        }

        return R.failed("");
    }
}
